
<script setup lang="ts">
import { ref, reactive, onMounted, inject } from 'vue'

import emitter from '@/utils/eventBus'

const showGasDailg = inject('showGasDialog') as (tyep:number, dataId:number) => {}

// props
const props = defineProps({
  dataId: {
    type: Number,
    default: null
  },
  posi: {
    type: Number,
    default: 0
  }
})

// 定义变量

const CONum = ref(0)
const CH4Num = ref(0)
const SmokeNum = ref(0)

const position = ref('')

// 定义方法
onMounted(() => {
  emitter.on('COData', showCoInfo)
  emitter.on('Ch4Data', showCh4Info)
  emitter.on('SmokeData', showSmokeInfo)
  switch (props.dataId) {
  case 31:
    if (!props.posi) {
      position.value = '21'
    } else {
      position.value = '11'
    }
    break
  case 32:
    if (!props.posi) {
      position.value = '23'
    } else {
      position.value = '13'
    }
    break
  case 33:
    if (!props.posi) {
      position.value = '25'
    } else {
      position.value = '15'
    }
    break
  case 34:
    if (!props.posi) {
      position.value = '27'
    } else {
      position.value = '17'
    }
    break
  case 35:
    if (!props.posi) {
      position.value = '29'
    } else {
      position.value = '19'
    }
    break
  }
})

const showCoInfo = (COData: any) => {
  let coData = COData.find((item: any) => {
    return (String(item.BarSectionId) + String(item.SensorNum)) === position.value
  })
  CONum.value = coData.Value
}
const showCh4Info = (CH4Data: any) => {
  let ch4Data = CH4Data.find((item: any) => {
    return (String(item.BarSectionId) + String(item.SensorNum)) === position.value
  })
  CH4Num.value = ch4Data.Value
}
const showSmokeInfo = (SmoketData: any) => {
  let smokeData = SmoketData.find((item: any) => {
    return (String(item.BarSectionId) + String(item.SensorNum)) === position.value
  })
  SmokeNum.value = smokeData.Value
  // console.log('数据----->', position.value, props.posi, SmokeNum )
}

// 引入依赖
const showIcon: any = inject('showIcon')
interface alarmDataIntef {
  CO: string,
  O2: string,
  CH4: string,
  smoke: string,
  dust: string,
  infrared: string
}
const alarmData: alarmDataIntef = inject('alarmData') as alarmDataIntef

</script>
<template>
  <el-popover
    placement="top-start"
    :width="154"
    trigger="hover"
  >
    <template #reference>
      <div
        
        class="three-item-main-box"
        @click="showGasDailg(3, props.dataId)"
      >
        <div
          v-show="showIcon.CO"
          :id="(String(CONum) < alarmData.CO) ? '' : (false ? 'gasFirstary' : 'gasSecondary')"
          class="co-box iconfont icon-yiyanghuatan"
        />
        <div
          v-show="showIcon.CH4"
          :id="(String(CH4Num) < alarmData.CH4) ? '' : (false ? 'gasFirstary' : 'gasSecondary')"
          class="ch4-box iconfont icon-jiawan"
        />
        <div
          v-show="showIcon.smoke"
          :id="(String(SmokeNum) < alarmData.smoke) ? '' : (false ? 'gasFirstary' : 'gasSecondary')"
          class="smoke-box iconfont icon-yangan"
        />
      </div>
    </template>
    <template #default>
      <div
        class="pop-box"
      >
        <div
          v-show="showIcon.CO"
          class="info-item"
        >
          <div
            :id="(String(CONum) < alarmData.CO) ? '' : (false ? 'gasFirstary' : 'gasAlarm')"
            class="co-num info-num"
          >
            {{ CONum }}
          </div>
          <div class="info-name">
            一氧化碳
          </div>
        </div>
        <div
          v-show="showIcon.CH4"
          class="info-item"
        >
          <div
            :id="(String(CH4Num) < alarmData.CH4) ? '' : (false ? 'gasFirstary' : 'gasAlarm')"
            class="ch4-num info-num"
          >
            {{ CH4Num }}
          </div>
          <div class="info-name">
            甲烷
          </div>
        </div>
        <div
          v-show="showIcon.smoke"
          class="info-item "
        >
          <div
            :id="(String(SmokeNum) < alarmData.smoke) ? '' : (false ? 'gasFirstary' : 'gasAlarm')"
            class="smoke-num info-num"
          >
            {{ SmokeNum }}
          </div>
          <div class="info-name">
            烟感
          </div>
        </div>
        <!-- <div class="info-item">
          <div class="dust-num info-num ">
            32%
          </div>
          <div class="info-name">
            粉尘
          </div>
        </div> -->
      </div>
    </template>
  </el-popover>
</template>

<style lang="scss" scoped>
.three-item-main-box {
  display: flex;
  justify-content: space-around;
  width: 96px;
  height: 40px;
  background: #f8fafd;
  border-radius: 54px;
  box-shadow: 0 4px 8px 0 rgb(166 184 208 / 40%);
  opacity: 1;
  > div {
    width: 24px;
    height: 24px;
    margin-top: 8px;
    line-height: 24px;
    text-align: center;
    background: linear-gradient(180deg, #54aafe 0%, #4482ed 100%);
    border-radius: 24px;
    box-shadow: 0 2px 4px 0 #bbd2ff;
    opacity: 1;
  }
}
.three-item-main-box:hover {
  cursor: pointer;
}
.pop-box {
  .info-item {
    .info-num {
      color: #fff;
      font-family: Ding,sans-serif;
    }
  }
}
</style>
